package com.xiongwei.factory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 简单工厂模式
 * 一个披萨项目：要求便于种类扩展，便于维护
 * 1.披萨种类：GreekPizza, CheesePizza等
 * 2.制作过程：prepare,bake,cut,box
 * 3.完成披萨订购
 * @author xiongwei
 */
public class OrderPizza2 {

    public OrderPizza2() {
        String orderType;
        do {
            orderType = getType();
            Pizza pizza = SimpleFactory.createPizza(orderType);
            if (pizza != null) {
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            } else {
                System.out.println("订购失败");
            }
        } while (true);

    }

    /**
     * 客户键入pizza种类
     * @return
     */
    public String getType() {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("请输入pizza种类");
        String s = null;
        try {
            s = bufferedReader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return s;
    }
}
